package c.h.b.c.a;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
import c.f.c.a.f;
import c.h.b.d.a.a;
import c.h.b.d.a.b;
import c.h.b.d.a.c;
import c.h.b.d.a.e;
import c.h.b.d.a.g;
import c.h.b.d.a.h;
import c.h.b.d.a.i;
import com.huawei.hms.iap.Iap;
import com.huawei.hms.iap.entity.OrderStatusCode;
import com.huawei.hms.iap.entity.OwnedPurchasesReq;
import com.huawei.hms.iap.entity.ProductInfoReq;
import com.huawei.hms.iap.entity.PurchaseIntentReq;
import com.huawei.hms.iap.entity.PurchaseResultInfo;
import com.liuzh.deviceinfo.pro.ProActivity;
import com.liuzh.deviceinfo.pro.ProActivity.d;
import java.util.List;
import java.util.Objects;

/* compiled from: HwIap */
public class j implements c {
    public void a(Intent intent, a aVar) {
        if (intent == null) {
            Objects.requireNonNull((ProActivity.c) aVar);
            return;
        }
        if (intent.getIntExtra("returnCode", 1) == 0) {
            ProActivity.c cVar = (ProActivity.c) aVar;
            ProActivity proActivity = ProActivity.this;
            e eVar = proActivity.r;
            if (eVar == null) {
                proActivity.E(false);
                ProActivity.A(ProActivity.this, "devinfo_vip", cVar.a, cVar.b);
            } else if (cVar.a) {
                proActivity.D(eVar.a);
            }
        } else {
            Objects.requireNonNull((ProActivity.c) aVar);
        }
    }

    public void b(Context context, Intent intent, b bVar) {
        if (intent == null) {
            ((d) bVar).a();
            return;
        }
        PurchaseResultInfo parsePurchaseResultInfoFromIntent = Iap.getIapClient(context).parsePurchaseResultInfoFromIntent(intent);
        int returnCode = parsePurchaseResultInfoFromIntent.getReturnCode();
        d dVar;
        if (returnCode == 0) {
            parsePurchaseResultInfoFromIntent.getInAppPurchaseData();
            parsePurchaseResultInfoFromIntent.getInAppDataSignature();
            dVar = (d) bVar;
            Objects.requireNonNull(dVar);
            c.h.a.f0.j.d.g();
            Toast.makeText(ProActivity.this, 2131690177, 0).show();
        } else if (returnCode == OrderStatusCode.ORDER_STATE_CANCEL) {
            Toast.makeText(ProActivity.this, 2131689740, 0).show();
        } else if (returnCode != OrderStatusCode.ORDER_PRODUCT_OWNED) {
            ((d) bVar).a();
        } else {
            dVar = (d) bVar;
            Objects.requireNonNull(dVar);
            c.h.a.f0.j.d.g();
            Toast.makeText(ProActivity.this, 2131690177, 0).show();
        }
    }

    public void c(Context context, int i, g gVar) {
        OwnedPurchasesReq ownedPurchasesReq = new OwnedPurchasesReq();
        ownedPurchasesReq.setPriceType(i);
        f obtainOwnedPurchases = Iap.getIapClient(context).obtainOwnedPurchases(ownedPurchasesReq);
        obtainOwnedPurchases.c(new g(gVar));
        obtainOwnedPurchases.a(new f(gVar));
    }

    public void d(Context context, int i, List<String> list, h hVar) {
        ProductInfoReq productInfoReq = new ProductInfoReq();
        productInfoReq.setPriceType(i);
        productInfoReq.setProductIds(list);
        f obtainProductInfo = Iap.getIapClient(context).obtainProductInfo(productInfoReq);
        obtainProductInfo.c(new i(hVar));
        obtainProductInfo.a(new b(hVar));
    }

    public void e(Context context, String str, int i, c.h.b.d.a.f fVar) {
        PurchaseIntentReq purchaseIntentReq = new PurchaseIntentReq();
        purchaseIntentReq.setProductId(str);
        purchaseIntentReq.setPriceType(i);
        purchaseIntentReq.setDeveloperPayload("test");
        f createPurchaseIntent = Iap.getIapClient(context).createPurchaseIntent(purchaseIntentReq);
        createPurchaseIntent.c(new c(this, fVar));
        createPurchaseIntent.a(new e(fVar));
    }

    public void f(Context context, i iVar) {
        f isEnvReady;
        Activity activity = context instanceof Activity ? (Activity) context : null;
        if (activity == null) {
            isEnvReady = Iap.getIapClient(context).isEnvReady();
        } else {
            isEnvReady = Iap.getIapClient(activity).isEnvReady();
        }
        a aVar = new a(iVar);
        d dVar = new d(iVar);
        if (activity == null) {
            isEnvReady.c(dVar);
            isEnvReady.a(aVar);
            return;
        }
        c.f.c.a.j.f fVar = (c.f.c.a.j.f) isEnvReady;
        Objects.requireNonNull(fVar);
        c.f.c.a.h hVar = c.f.c.a.h.d;
        c.f.c.a.j.e eVar = new c.f.c.a.j.e(hVar.c, dVar);
        c.f.c.a.j.d.a(activity, eVar);
        fVar.h(eVar);
        c.f.c.a.j.f fVar2 = (c.f.c.a.j.f) isEnvReady;
        c.f.c.a.j.c cVar = new c.f.c.a.j.c(hVar.c, aVar);
        c.f.c.a.j.d.a(activity, cVar);
        fVar2.h(cVar);
    }
}
